<?php
include ("../include/config.php");
require($config['basedir']."/include/authenticate.php");
require($config['basedir']."/admin/classes/expense.class.php");
$post = $_REQUEST;
$objSL = new Expense();

$_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';

switch($_action) {

	case 'add':
		if (isset($post['submit']))
		{
			$objSL->addExpense($post);
		}
		stemplate::assign("post", $post);		
		stemplate::display("admin/expense/save_expense.tpl");
	break;
	
	case 'edit':
		$expense = $objSL->getExpenseById($post['expense_id']);
		if (isset($post['submit']))
		{
			$objSL->updateExpense($post);
		}
		stemplate::assign("expense", $expense);
		stemplate::assign("post", $post);		
		stemplate::display("admin/expense/save_expense.tpl");
		
	break;
	
	case 'update_order':
		$objSL->updateOrder($post);
	break;
	
	case 'delete':
		$objSL->deleteExpense($post);
	break;
	
	case 'confirmStatus':
		$objSL->confirmStatus($post);
	break;
	
	case 'view':
	default:
		global $pager;
		$data = $_REQUEST;
		
		if($_REQUEST['added'] == 1)	{
			global $msgOk;
			$msgOk = 'Record added successfully';
		}elseif($_REQUEST['updated'] == 1){
			global $msgOk;
			$msgOk = 'Record updated successfully';
		}elseif($_REQUEST['deleted'] == 1){
			global $msgOk;
			$msgOk = 'Record deleted successfully';
		}elseif($_REQUEST['deleted'] == 'error'){
			global $msgError;
			$msgError = 'Cannot delete Record. It is associated with paid bill.';
		}
		
		stemplate::assign("expenses",  $objSL->getExpenses());
		stemplate::assign("post", $post);
		stemplate::display("admin/expense/list_expense.tpl");
    break; 
	
}




?>